package pers.lls.hds.linklist;


/**
 * 链表的基本实现
 *
 * @author lilichai
 */
public class LinkedList<E> {

    class Node<E> {
        E obj;
        Node<E> next;
        public Node(E obj) {
            this.obj = obj;
        }
    }

    private Node<E> first;

    public LinkedList() {
        first = null;
    }

    public void insertFirst(E e) {
        Node<E> links = new Node<>(e);
        links.next = first;
        first = links;
    }

    public Node<E> deleteFirst() {
        Node<E> temp = first;
        first = first.next;
        return temp;
    }

    public boolean isEmpty() {
        return (first == null);
    }

    public void display() {
        Node<E> current = first;
        while (current != null) {
            System.out.println(current.obj);
            current = current.next;
        }
    }

    public static void main(String[] args) {
        LinkedList list = new LinkedList<Integer>();
        list.insertFirst(3);
        list.insertFirst(5);
        list.insertFirst(4);
        list.deleteFirst();
        list.display();

    }
}




